//
//  LOLUserMessageView.m
//  LOL_Little_Box
//
//  Created by dllo on 16/3/24.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LOLUserMessageView.h"
#import "LOLImageView.h"
#import "LOLLabel.h"
#import "LOLButton.h"

@interface LOLUserMessageView ()

@property (nonatomic , retain)LOLImageView *imageUser;
@property (nonatomic , retain)LOLImageView *imageBg;
@property (nonatomic , retain)LOLButton *buttonCommunity;
@property (nonatomic , retain)LOLLabel *labelName;

@end

@implementation LOLUserMessageView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageBg = [[LOLImageView alloc]initWithFrame:CGRectZero];
        self.imageUser = [[LOLImageView alloc]initWithFrame:CGRectZero];
        self.labelName = [[LOLLabel alloc]initWithFrame:CGRectZero];
        self.buttonCommunity = [[LOLButton alloc]initWithFrame:CGRectZero];
        
        self.imageBg.image = [UIImage imageNamed:@"personal_social_bg"];
        self.imageUser.image = [UIImage imageNamed:@"personal_guide_center"];
        self.labelName.text = @"夜不知枫";
        self.labelName.textColor = [UIColor whiteColor];
        self.labelName.font = [UIFont systemFontOfSize:15.0];
        [self.buttonCommunity setBackgroundImage:[[UIImage imageNamed:@"personal_guide_social"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
        
        [self addSubview:self.imageBg];
        self.imageBg.userInteractionEnabled = YES;
        /**为背景图添加手势，点击就进入二级界面 */
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapMoveToUserDetial)];
        
        [self.buttonCommunity addTarget:self action:@selector(tapMoveToUserDetial) forControlEvents:UIControlEventTouchUpInside];
        
        self.imageUser.userInteractionEnabled = YES;
        [self.imageBg addGestureRecognizer:tap];
        [self.imageBg addSubview:self.imageUser];
        [self.imageBg addSubview:self.labelName];
        [self.imageBg addSubview:self.buttonCommunity];
    }
    return  self;
}

- (void)tapMoveToUserDetial{
    /**使用协议方法，在vc界面跳转到我的user的详情界面 */
    [self.delegate jumpToUserDetialPager];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    /**根据屏幕的大小动态的修改尺寸，，也可能需要放在初始化函数中 */
    CGSize size = CGSizeMake(50, 50);
    CGRect frame ;
    frame.origin = CGPointMake(20, 20);
    frame.size = size;
    self.imageUser.frame = frame;
    
    CGPoint center = self.imageUser.center;
    center.y = self.center.y;
    self.imageUser.center = center;
    
    frame.size = self.frame.size;
    frame.origin = CGPointMake(0, 0);
    self.imageBg.frame = frame;
    
    /**label和button  frame*/
    frame.origin = CGPointMake(80, 25);
    frame.size = CGSizeMake(150, 20);
    self.labelName.frame = frame;
    self.labelName.backgroundColor = [UIColor clearColor];
//    center = self.labelName.center;
//    center.y = self.center.y;
//    self.labelName.center = center;
    
    UIImage *image = [UIImage imageNamed:@"personal_guide_social"];
    frame.origin.x = self.frame.size.width - (10 + [image size].width);
    frame.size = image.size;
    self.buttonCommunity.frame = frame;
    center = self.buttonCommunity.center;
    center.y = self.center.y;
    self.buttonCommunity.center = center;
    
}

@end
